<template>
	<view class="menu">
		<view class="menu-list">
			<view class="menu-item" v-for="(item,index) in homeMenuData" :key="index" @click="toChatDetail(item)">
				<view class="menu-icon">
					<u-image :src="item.icon" width="100%" height="100%" />
				</view>
				<view class="menu-label">
					{{item.title}}
				</view>
			</view>
			<view class="placeholder" v-if="menuList.length%4!=0">

			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			homeMenuData: {
				type: Array
			}
		},
		data() {
			return {}
		},
		methods: {
			async toChatDetail(item) {
				console.log(item)
				if (this.userInfo && (this.userInfo.is_lawyer == 1 || this.userInfo.is_service == 1)) {
					return this.$showToast('律师身份不能发起咨询')
				}
				this.$u.post(this.$restUrl.consultTimepiece, {
					type_id: item.id,
				}).then(res => {
					console.log(this.userInfo.nickname+'的'+item.title + '咨询')
					const session = {
						sessionId: res.data.groupid,
						sessionName: this.userInfo.nickname+'的'+item.title + '咨询',
						chatType: 'groupChat',
					}

					this.$u.route(`/pages_chat/chat_detail/chatDetail?sessionInfo=${encodeURIComponent(JSON
						.stringify(session))}`);
				}).catch(err => {
					if (err.status_code == 404) {
						const session = {
							sessionName: `${item.title}咨询`,
							quick_reply: item.quick_reply,
							quick_reply_second: item.quick_reply_second,
							quick_reply_third:item.quick_reply_third,
							id: item.id,
						}
						this.$u.route(`/pages_chat/static_chat/staticChat?sessionInfo=${encodeURIComponent(JSON
								.stringify(session))}`);
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	@import "./menu.scss";
</style>
